home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / citsrc6K05.lha / vexfind.c < prev    next >
C/C++ Source or Header  |  1996-11-05  |  4KB  |  181 lines

  1. /*
  2.                                VexFind.c
  3.  DESCRIPTION:
  4.  This utility will report on *all* or individual systems in
  5.  the vortex information.  It will list the messages in the
  6.  order they were recieved.  If no rooms are listed on the command
  7.  line, then all rooms will be reported.  If rooms are listed only
  8.  those rooms will be reported on.
  9.  
  10.  To remove dependancy on the CTDL database, this utility must
  11.  be run from the vortex directory in the netarea. This eliminates
  12.  reading the CTDLTABL.SYS file and all sorts of overhead.
  13.  
  14.  */
  15. #include "ctdl.h"    /* header file  */
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #include "vortex.h"
  20. #include <dos.h>
  21. /*
  22.  * main()
  23.  *
  24.  * This is the main manager.
  25.  */
  26. int main(int, char **);
  27. void Process_Rooms(void);
  28. void Process_Room(char *room);
  29.  
  30. int main(argc, argv)
  31. int  argc;
  32. char **argv;
  33. {
  34.     int i;
  35.     printf("Citadel Vortex Data Report %s-%s\n",VERSION_NAME, COPYRIGHT);
  36.     if ( argc == 1 )
  37.       {
  38.       Process_Rooms();
  39.       }
  40.     else
  41.       {
  42.       for(i=1; i<argc; i++) Process_Room(argv[i]);
  43.       };
  44.   return 0;
  45. }
  46.  
  47. /*
  48.  * crashout()
  49.  *
  50.  * Fatal error handler.
  51.  */
  52. void crashout(char *str)
  53. {
  54.     exit(printf("%s\n", str));
  55. }
  56.  
  57. struct Entries
  58.   {
  59.   struct Entries *next; /* link to next entry */
  60.   char *name;           /* pointer to the name of the vortex file(room name) */
  61.   };
  62.  
  63. void Process_Rooms(void)
  64. /**
  65.   Description:  Get a directory listing of the vortex directory
  66.   and call Process_Room() with each name found.
  67. **/
  68.   {
  69.   struct Entries *Head;  /* current level head */
  70.   struct Entries *Last;  /* current level tail */
  71.   struct Entries  *litem, *citem, *nitem;
  72.   struct FileInfoBlock *info;
  73.   char *filename;              /* set to all files ending in .hlp */
  74.   short not_done;
  75.   int error,attr;
  76.  
  77.   Head = NULL;
  78.   filename = "#?";
  79.  
  80.   info  = (struct FileInfoBlock *)calloc(1,sizeof(struct FileInfoBlock));
  81.   attr  = 0;    /* find all files, no directories */
  82.   error = dfind(info,filename,attr);  /* get first one*/
  83.  
  84.   while( error == 0 )
  85.     {
  86.     citem = (struct Entries *)calloc(1,sizeof(struct Entries));
  87.     if( Head == NULL )
  88.       {
  89.       Last = Head = citem;
  90.       }
  91.     else
  92.       {
  93.       Last->next = citem;
  94.       Last = citem;
  95.       };
  96.     citem->name = strdup(info->fib_FileName);
  97.     error = dnext(info);
  98.     };
  99.   /* sort the directory list into alphabetical order */
  100.   if( Head->next != NULL )
  101.     {
  102.     not_done = TRUE;
  103.     while ( not_done )
  104.       {
  105.       not_done = FALSE;
  106.       litem = NULL;
  107.       citem = Head;
  108.       nitem = citem->next;
  109.       while ( nitem != NULL )
  110.         {
  111.         if( strcmpi(nitem->name,citem->name) < 0 )
  112.           {
  113.           not_done = TRUE;
  114.           if( litem == NULL )
  115.             {
  116.             Head = litem = nitem;
  117.             }
  118.           else litem->next = nitem;
  119.           citem->next = nitem->next;
  120.           nitem->next = citem;
  121.           };
  122.         litem = citem;
  123.         citem = nitem;
  124.         nitem = citem->next;
  125.         };
  126.       };
  127.     };
  128.   /**
  129.     Now Report on Each Room
  130.   **/
  131.   while( Head )
  132.     {
  133.     Process_Room(Head->name);
  134.     Head = Head->next;
  135.     };
  136.   }
  137.  
  138. int first_flag = TRUE;
  139.  
  140. void Process_Room(char *room)
  141.   {
  142.   /**
  143.     Given a room name, a file in the current directory,
  144.     open the file and report the contents.
  145.   **/
  146.   ROOM_ENTRY_TYPE record;
  147.   FILE *ip;
  148.   int start;
  149.   int count;
  150.   if( (ip=fopen(room,"r")) == NULL )
  151.     {
  152.     printf("Error: could not open room %s\n",room);
  153.     }
  154.   else
  155.     {
  156.     if( fread(&record, sizeof(ROOM_ENTRY_TYPE), 1, ip) != 1 )
  157.       {
  158.       printf("Error:  could not read the vortex record for %s\n",room);
  159.       }
  160.     else
  161.       {
  162.       start = ( record.index < MAX_VORTEX_SIZE ) ? 0 : record.next_slot;
  163.       count = record.index;
  164.       if( first_flag )
  165.         {
  166.         first_flag = FALSE;
  167.         printf("%-20s %7s %8s %12s %s\n","Room", "Date", "Time","Id", "Orig");
  168.         };
  169.       while( count-- )
  170.         {
  171.         printf("%-20s %7s %8s %12s %s\n", room , record.msg_entry[start].mbdate
  172.         , record.msg_entry[start].mbtime, record.msg_entry[start].mbsrcId
  173.         , record.msg_entry[start].mborig);
  174.         start = (start + 1 ) % MAX_VORTEX_SIZE;
  175.         };
  176.       };
  177.     fclose(ip);
  178.     };
  179.   }
  180.  
  181.